package com.googlecode.spreadit.bean;

/**
 * A {@link SpreadChannel} is the type of media used for forwarding a given
 * message.
 * 
 * @author Markus L. Dechert (markus.dechert@googlemail.com)
 */
public enum SpreadChannel {
	SMS("SMS"), EMAIL("E-Mail"), WHATSAPP("WhatsApp");

	private String title;

	private SpreadChannel(String title) {
		this.title = title;
	}

	/**
	 * Returns the title of this {@link SpreadChannel}.
	 */
	@Override
	public String toString() {
		return title;
	}

	/**
	 * Returns the {@link SpreadChannel} enum object with the passed title or
	 * <code>null</code> if no SpreadChannel with the given title exists. The
	 * comparison is not case sensitive.
	 * 
	 * @param title
	 *            the title of the {@link SpreadChannel} that the caller wants
	 *            to get.
	 * @return the respective {@link SpreadChannel} or <code>null</code> (see
	 *         above).
	 */
	public static SpreadChannel getByTitle(String title) {
		SpreadChannel result = null;
		for (SpreadChannel sc : SpreadChannel.values()) {
			if (sc.toString().equalsIgnoreCase(title)) {
				result = sc;
				break;
			}
		}
		return result;
	}

}